package tk.hongbo.rainbow

import org.junit.Assert.assertEquals
import org.junit.Test

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
class ExampleUnitTest {
    @Test
    fun addition_isCorrect() {
        assertEquals(4, 2 + 2)
    }

    /**
     * 找出异常数字
     */
    @Test
    fun findStrangeNum() {
        val data = intArrayOf(1, 3, 2, 3)
//        val data = intArrayOf(1, 3, 2, 4)
//        val data = intArrayOf(1, 3, 2, -1)
        val list = arrayListOf<Int>()
        for (th in data) {
            if (th < 1 || th > data.size - 1 || list.contains(th)) {
                println("====>${th}")
            }
            list.add(th)
        }
    }

    //冒泡排序
    @Test
    fun bubbleSort() {
        val data = intArrayOf(1, 3, 2, 3)
        var temp: Int
        for (i in data.indices) {
            for (j in 0..data.size - 2 - i) {
                if (data[j] < data[j + 1]) {
                    temp = data.get(j)
                    data[j] = data.get(j + 1)
                    data[j + 1] = temp
                }
            }
        }
        println(data.toString())
    }
}